<!--
 * @FileDescription: 登陆页面
 * @Author: yijiamu
 * @Date: 2022-05-16 08:22:18
 * @LastEditors: yijiamu
 * @LastEditTime: 2022-05-16 08:22:18
 -->

<template>
  <div class="wps">
    <header class="head">
      <div class="head_logo">
        <span class="logo"></span>
      </div>
    </header>
    <main class="main">
      <div class="main_item">
        <div class="nav">
          <span class="nav_title">账号密码登录</span>
        </div>
        <div class="login_info">
          <div class="info_item">
            <input class="info_input" v-model="account" placeholder="用户名" type="text">
          </div>
          <div class="info_item password">
            <input class="info_input" v-model="pwd" placeholder="密码" type="password">
          </div>
          <div class="register">
            <router-link to="/register">
              <div>
              注册新帐号
              </div>
            </router-link>
            <br>
            <button class="login_btn" @click="login">立即登录</button>
          </div>
        </div>
      </div>
    </main>
  </div>
</template>

<script>

import { loginIn } from '@/api/auth/api'
import { getUserInfo } from '@/api/user/api'

export default {
  name: 'login-com',
  data(){
    return{
        account:'', //用户名
        pwd:'',       //密码
    }
  },
  methods: {
  /**
    /*
    * @description: 登录函数
    */
    async login() {
      try {
        await loginIn(this.account,this.pwd)   //登录结果
        try {
          let userInfo = await getUserInfo()  //获取用户信息
          if (userInfo.stat === 'ok'){          //如果登录成功将用户的个人信息
            this.$store.commit('SAVEUSERINFO',userInfo.data.user);
            this.$router.push('/form-list')
          }
        }catch (e) {
          alert('用户获取错误，请重新登陆！')            //登录失败提示
        }
      } catch (e) {
        alert('账号或密码错误')            //登录失败提示
      }
    },
  },
}
</script>

<style lang="scss" scoped>

 // 外部容器
.wps {
  position: relative;
  height: 100%;
  font-size: 14px;
  color: #535252;
  padding-top: .1px;

  // head
  .head {
    background-color: #fff;
    border-bottom: 1px solid #e9e9e9;

    // logo容器
    .head_logo {
      display: flex;
      height: 56px;
      max-width: 1180px;
      margin: 0 auto;
      align-items: center;

      // logo
      .logo {
        display: inline-block;
        margin-left: 64px;
        vertical-align: top;
        width: 88px;
        height: 22px;
        background-image: url(//ac.wpscdn.cn/account/libs/img/v1/logo.676137dd.png);
      }
    }
  }

  // 登录注册
  .main {
    overflow: hidden;
    width: 358px;
    margin: 90px auto 0;
    text-align: center;
    background: #fff;
    border-radius: 4px;
    border: 1px solid #d8d8d8;
    position: relative;

    .main_item {
      overflow: visible;
      position: relative;
      width: 260px;
      min-height: 408px;
      margin: 0 auto;

        // 登录、注册标题容器
      .nav {
        text-align: center;
        padding-top: 37px;

        // 登录、注册标题
        .nav_title {
          font-size: 18px;
          line-height: 24px;
          color: #535252;
        }
      }

      // 登录信息
      .login_info {
        margin-top: 31px;
        display: block;
        text-align: left;
        width: 100%;
        position: relative;

        // 输入框容器
        .info_item {
          position: relative;
            // margin-top: 22px;
          width: 100%;
          background: #fff;
          border-radius: 3px;

          // 输入框
          .info_input {
            display: block;
            width: 234px;
            font-size: 14px;
            line-height: 24px;
            padding: 9px 12px;
            border: 1px solid #d8d8d8;
            border-radius: 3px;
            position: relative;
            background-color: transparent;
            background-image: url();
            font-family: inherit;
            font-weight: inherit;

            input::placeholder {
              color: #a8a8a8;
            }
          }
        }

        .password {
          margin-top: 10px;
        }

        .register{
          height: 30px;
          line-height: 20px;
          margin-top: 20px;
          text-align: left;

          a {
          text-decoration: none;
          color: #417FF9;
          }

          // 登录按钮
          .login_btn{
            width: 260px;
            line-height: 44px;
            font-size: 14px;
            background-color: #1E86E7;
            color: #fff;
            border-radius: 4px;
            border-style: none;
            padding: 0;
            margin-top: 30px;
          }
        }
      }
    }
  }
}

// 媒体查询
@media only screen and (max-width: 480px) {

  .head,
  .nav {
    display: none;
  }

  .wps .main {
    border: none;
    margin-top: 0;
    height: 100%;
    width: 100%;
    background-color: transparent;
    overflow: auto;

  }

  .main_item {
    height: auto;
  }

  .login_info {
    padding-top: 0;
  }

  .wps .main .main_item .login_info .info_item .info_inpu,
  .wps .main .main_item .login_info .register .login_btn {
    border-radius: 5px;
    margin-top: 14px;
  }
}

</style>
